package com.mybd.req.four;

import com.mybd.req.three.EmployeeInformation;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author: Scq
 * @time: 2021/6/510:59
 */
public class MyMapper extends Mapper<LongWritable, Text, Text, NullWritable> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] split = value.toString().split(",");
        String date = split[split.length - 4];
        // 17-12月-80
        String[] dateSplit = date.split("-");
        String month = dateSplit[1].replace("月", "");
        String day = dateSplit[0];
        String year = "19" + dateSplit[2];
        if (Integer.parseInt(month) < 10) {
            month = "0" + month;
        }
        split[split.length - 4] = year + "-" + month + "-" + day;
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < split.length; i++) {
            stringBuilder.append(split[i]);
            if (i == split.length - 1) {
                break;
            }
            stringBuilder.append(",");
        }
        context.write(new Text(stringBuilder.toString()), NullWritable.get());
    }
}
